using I2.Loc;
using UnityEngine;
using UnityEngine.UI;

public class CampaignFinish : MonoBehaviour
{
	public Counter counter;

	public Button rewardButton;

	public Text rewardButtonText;

	public IAPManager iapManager;

	public GameObject adFree;

	public Text adFreeTextView;

	public bool playerAdFreeWhenStart;

	public bool playerAdFreeRewarded;

	public int baseReward;

	private bool noSuperReward;

	public bool NoSuperReward
	{
		get
		{
			return noSuperReward;
		}
		set
		{
			noSuperReward = value;
		}
	}

	private void Awake()
	{
		if (Config.initialized)
		{
			new Config().Init();
		}
		counter.number = DO.Campaign.dayIncome;
		if (DO.Player.adFree)
		{
			SuperReward();
		}
		if (DO.Campaign.dayIncomeRewarded > 0)
		{
			counter.number += DO.Campaign.dayIncomeRewarded;
			rewardButton.gameObject.SetActive(value: false);
		}
	}

	public void VideoSuperReward()
	{
		SuperReward();
		if ((bool)counter)
		{
			counter.number = DO.Campaign.dayIncome + DO.Campaign.dayIncomeRewarded;
			counter.countInSecond = 0.2f;
			counter.StartCounter();
		}
	}

	public void SuperReward()
	{
		if (!NoSuperReward)
		{
			rewardButton.gameObject.SetActive(value: false);
			GameObject.Find("Title").GetComponent<Text>().text = LocalizationManager.GetTranslation("SuperReward");
			DO.Campaign.dayIncomeRewarded = Mathf.CeilToInt((float)DO.Campaign.dayIncome * (Config.videoReward - 1f));
			DO.Campaign.balance += DO.Campaign.dayIncomeRewarded;
			DO.Campaign.totalIncome += DO.Campaign.dayIncomeRewarded;
			string content = JsonUtility.ToJson(DO.Campaign);
			SaveLoad.SaveString("Campaign", content);
		}
	}

	private void Start()
	{
		playerAdFreeWhenStart = DO.Player.adFree;
		if ((bool)GameObject.Find("BackgroundMusic"))
		{
			GameObject.Find("BackgroundMusic").GetComponent<BackgroundMusic>().active = true;
		}
		counter.StartCounter();
		adFree.gameObject.SetActive(value: false);
	}

	public void RewardBtnReady()
	{
		rewardButton.interactable = true;
		rewardButtonText.text = LocalizationManager.GetTranslation("SuperRewardButton").Replace("{AMOUNT}", Mathf.CeilToInt((float)DO.Campaign.dayIncome * Config.videoReward).ToString("n0"));
	}

	public void RewardBtnNotReady()
	{
		rewardButton.interactable = false;
		rewardButtonText.text = LocalizationManager.GetTranslation("SuperRewardUnavailable");
	}

	private void Update()
	{
		// if (!NoSuperReward && DO.Player.adFree)
		// {
		// 	adFree.SetActive(value: false);
		// 	rewardButton.gameObject.SetActive(value: false);
		// 	if (!playerAdFreeRewarded && DO.Campaign.dayIncomeRewarded <= 0 && !playerAdFreeWhenStart && !iapManager.alert.canvas.enabled)
		// 	{
		// 		SuperReward();
		// 		counter.number = DO.Campaign.dayIncome + DO.Campaign.dayIncomeRewarded;
		// 		counter.countInSecond = 0.2f;
		// 		counter.StartCounter();
		// 		rewardButton.gameObject.SetActive(value: false);
		// 		playerAdFreeRewarded = true;
		// 	}
		// }
	}

	public void Continue()
	{
		Initiate.Fade("CampaignShop", Color.black, 5f);
	}

	public void CounterDone()
	{
		if (DO.Campaign.dayIncomeRewarded > 0)
		{
			counter.GetComponent<Animator>().Play("CounterDoneSuper");
		}
		else
		{
			counter.GetComponent<Animator>().Play("CounterDone");
		}
	}
}
